const { getUserById } = require("../service/user")
const { AssertUtils } = require("../util/utils")

module.exports = async (ctx, next) => {
  if (ctx?.state?.user) {
    let user = await getUserById(ctx.state.user.id)
    AssertUtils.ObjectNotEmpty(user, "用户过期", 401)
    ctx.state.current = user
  }
  await next()
}